home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / amiga.free / diropus4.12b_gpl / config / screen_screenmode.c < prev    next >
C/C++ Source or Header  |  2000-01-27  |  10KB  |  306 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "config.h"
  32.  
  33. initscreenmodes()
  34. {
  35.     int pal,count,minw,minh,defw,depth,needdef=0,overx,overy,oldcount=0;
  36.     struct Screen scrbuf,*wbscreen;
  37.     char buf[256],namebuf[180];
  38.     struct DimensionInfo *dimension;
  39.     DisplayInfoHandle *handle;
  40.     struct List *pubscreenlist;
  41.     struct PubScreenNode *pubscreen;
  42.     ULONG modeid;
  43.  
  44.     dimension=(struct DimensionInfo *)buf;
  45.     count=0; depth=4;
  46.  
  47.     if (version2 && (wbscreen=LockPubScreen("Workbench"))) {
  48.         modeid=GetVPModeID(&(wbscreen->ViewPort));
  49.         if ((handle=FindDisplayInfo(modeid))) {
  50.             GetDisplayInfoData(handle,buf,256,DTAG_DIMS,0);
  51.             depth=dimension->MaxDepth;
  52.         }
  53.         UnlockPubScreen(NULL,wbscreen);
  54.     }
  55.     GetWBScreen(&scrbuf);
  56.  
  57.     if (version2) {
  58.         modeid=INVALID_ID;
  59.         while ((modeid=NextDisplayInfo(modeid))!=INVALID_ID) {
  60.             if (!ModeNotAvailable(modeid) &&
  61.                 (handle=FindDisplayInfo(modeid)) &&
  62.                 (GetDisplayInfoData(handle,namebuf,128,DTAG_NAME,0)) &&
  63.                 (GetDisplayInfoData(handle,buf,256,DTAG_DIMS,0))) {
  64.                 if (modeid&HIRES_KEY || modeid&HIRESLACE_KEY) minw=640;
  65.                 else {
  66.                     minw=dimension->MinRasterWidth;
  67.                     if (minw<160) minw*=10;
  68.                 }
  69.                 minh=dimension->MinRasterHeight; if (minh<200) minh=200;
  70.                 defw=(dimension->TxtOScan.MaxX-dimension->TxtOScan.MinX)+1;
  71.                 if (minw>=640 && defw>=640) {
  72.                     count+=addscreenmode(((struct NameInfo *)namebuf)->Name,
  73.                         minw,minh,
  74.                         dimension->MaxRasterWidth,dimension->MaxRasterHeight,
  75.                         defw,(dimension->TxtOScan.MaxY-dimension->TxtOScan.MinY)+1,
  76.                         dimension->MaxDepth,modeid);
  77.                 }
  78.             }
  79.         }
  80.         if (count==0) needdef=1;
  81.         else {
  82.             sortscreenmodes(count,0);
  83.             oldcount=count;
  84.         }
  85.         if (pubscreenlist=LockPubScreenList()) {
  86.             pubscreen=(struct PubScreenNode *)pubscreenlist->lh_Head;
  87.             while (pubscreen->psn_Node.ln_Succ) {
  88.                 if (strcmp(pubscreen->psn_Node.ln_Name,"Workbench")!=0 &&
  89.                     pubscreen->psn_Screen->Width>=640 &&
  90.                     pubscreen->psn_Screen->Height>=200 &&
  91.                     pubscreen->psn_Screen->RastPort.BitMap->Depth>1) {
  92.  
  93.                     lsprintf(namebuf,"%s:%s",pubscreen->psn_Node.ln_Name,cfg_string[STR_SCREEN_MODE_USE]);
  94.                     count+=addscreenmode(namebuf,
  95.                         640,200,
  96.                         pubscreen->psn_Screen->Width,pubscreen->psn_Screen->Height,
  97.                         pubscreen->psn_Screen->Width,pubscreen->psn_Screen->Height,
  98.                         pubscreen->psn_Screen->RastPort.BitMap->Depth,MODE_PUBLICSCREENUSE);
  99. /*
  100.                     modeid=GetVPModeID(&pubscreen->psn_Screen->ViewPort);
  101.                     if ((handle=FindDisplayInfo(modeid))) {
  102.                         GetDisplayInfoData(handle,buf,256,DTAG_DIMS,0);
  103.                         a=dimension->MaxDepth;
  104.                     }
  105.                     else a=4;
  106.  
  107.                     lsprintf(namebuf,"%s:%s",pubscreen->psn_Node.ln_Name,cfg_string[STR_SCREEN_MODE_CLONE]);
  108.                     count+=addscreenmode(namebuf,
  109.                         pubscreen->psn_Screen->Width,pubscreen->psn_Screen->Height,
  110.                         0,0,
  111.                         0,0,
  112.                         a,MODE_PUBLICSCREENCLONE);
  113. */
  114.                 }
  115.                 pubscreen=(struct PubScreenNode *)pubscreen->psn_Node.ln_Succ;
  116.             }
  117.             UnlockPubScreenList();
  118.         }
  119.     }
  120.     else needdef=1;
  121.  
  122.     if (needdef) {
  123.         pal=GfxBase->DisplayFlags&PAL;
  124.         overx=704-GfxBase->NormalDisplayColumns;
  125.         if (overx<0) overx=0;
  126.         overy=((pal)?290:240)-GfxBase->NormalDisplayRows;
  127.         if (overy<0) overy=0;
  128.  
  129.         count+=addscreenmode(pal?"PAL:High Res":"NTSC:High Res",
  130.             640,200,
  131.             GfxBase->NormalDisplayColumns+overx,GfxBase->NormalDisplayRows+overy,
  132.             GfxBase->NormalDisplayColumns,GfxBase->NormalDisplayRows,
  133.             4,HIRES_KEY);
  134.         count+=addscreenmode(pal?"PAL:High Res Laced":"NTSC:High Res Laced",
  135.             640,200,
  136.             GfxBase->NormalDisplayColumns+overx,(GfxBase->NormalDisplayRows+overy)*2,
  137.             GfxBase->NormalDisplayColumns,GfxBase->NormalDisplayRows*2,
  138.             4,HIRESLACE_KEY);
  139.     }
  140.  
  141.     count+=addscreenmode(cfg_string[STR_MODE_WORKBENCH_USE],
  142.         640,200,
  143.         scrbuf.Width,scrbuf.Height,
  144.         scrbuf.Width,scrbuf.Height,
  145.         scrbuf.RastPort.BitMap->Depth,MODE_WORKBENCHUSE);
  146.     count+=addscreenmode(cfg_string[STR_MODE_WORKBENCH_CLONE],
  147.         scrbuf.Width,scrbuf.Height,
  148.         0,0,
  149.         0,0,
  150.         depth,MODE_WORKBENCHCLONE);
  151.  
  152.     if (count>oldcount) sortscreenmodes(count-oldcount,oldcount);
  153.     return(count);
  154. }
  155.  
  156. addscreenmode(name,minw,minh,maxw,maxh,defw,defh,depth,mode)
  157. char *name;
  158. UWORD minw,minh,maxw,maxh,defw,defh,depth;
  159. ULONG mode;
  160. {
  161.     struct ScreenMode *scrmode;
  162.  
  163.     screenmode=firstmode;
  164.     while (screenmode) {
  165.         if (LStrCmpI(screenmode->name,name)==0) return(0);
  166.         if (!screenmode->next) break;
  167.         screenmode=screenmode->next;
  168.     }
  169.  
  170.     if (scrmode=LAllocRemember(&screenkey,sizeof(struct ScreenMode),MEMF_CLEAR)) {
  171.         if (screenmode) screenmode->next=scrmode;
  172.         else firstmode=scrmode;
  173.         strcpy(scrmode->name,name);
  174.         scrmode->minw=minw; scrmode->minh=minh;
  175.         if (maxw==0) scrmode->maxw=minw; else scrmode->maxw=maxw;
  176.         if (maxh==0) scrmode->maxh=minh; else scrmode->maxh=maxh;
  177.         if (defw==0) scrmode->defw=minw; else scrmode->defw=defw;
  178.         if (defh==0) scrmode->defh=minh; else scrmode->defh=defh;
  179.         scrmode->maxdepth=(depth>4)?4:depth;
  180.         scrmode->mode=mode;
  181.         return(1);
  182.     }
  183.     return(0);
  184. }
  185.  
  186. struct ScreenMode *showdisplaydesc()
  187. {
  188.     struct ScreenMode *mode;
  189.     char buf[80];
  190.  
  191.     SetAPen(rp,screen_pens[0].pen);
  192.     RectFill(rp,x_off+238,y_off+140,x_off+509,y_off+179);
  193.     SetAPen(rp,screen_pens[1].pen);
  194.     if (!(mode=getscreenmode(screenmodeview.itemselected))) return(NULL);
  195.     lsprintf(buf,"%-16s: %ld %s %ld",cfg_string[STR_MINIMUM_SIZE],mode->minw,cfg_string[STR_BY],mode->minh);
  196.     UScoreText(rp,buf,x_off+240,y_off+147,-1);
  197.     lsprintf(buf,"%-16s: %ld %s %ld",cfg_string[STR_MAXIMUM_SIZE],mode->maxw,cfg_string[STR_BY],mode->maxh);
  198.     UScoreText(rp,buf,x_off+240,y_off+155,-1);
  199.     lsprintf(buf,"%-16s: %ld %s %ld",cfg_string[STR_DEFAULT_SIZE],mode->defw,cfg_string[STR_BY],mode->defh);
  200.     UScoreText(rp,buf,x_off+240,y_off+163,-1);
  201.     lsprintf(buf,"%-16s: %ld",cfg_string[STR_MAXIMUM_COLORS],(1<<mode->maxdepth));
  202.     UScoreText(rp,buf,x_off+240,y_off+171,-1);
  203.     return(mode);
  204. }
  205.  
  206. void fixmodegads(mode)
  207. struct ScreenMode *mode;
  208. {
  209.     lsprintf(screenwidth_buf,"%ld",config->scrw);
  210.     lsprintf(screenheight_buf,"%ld",config->scrh);
  211.     if (config->scrdepth<2) config->scrdepth+=2;
  212.     if (config->scrdepth>((mode)?mode->maxdepth:4))
  213.         config->scrdepth=((mode)?mode->maxdepth:4);
  214.     lsprintf(screendepth_buf,"%ld",(1<<config->scrdepth));
  215.     if (mode && !(screenmodegads[SCREENMODE_WIDTH-300].Flags&GADGDISABLED)) {
  216.         if (!(CheckNumGad(&screenmodegads[SCREENMODE_WIDTH-300],Window,mode->minw,mode->maxw)))
  217.             RefreshStrGad(&screenmodegads[SCREENMODE_WIDTH-300],Window);
  218.     }
  219.     if (mode && !(screenmodegads[SCREENMODE_HEIGHT-300].Flags&GADGDISABLED)) {
  220.         if (!(CheckNumGad(&screenmodegads[SCREENMODE_HEIGHT-300],Window,mode->minh,mode->maxh)))
  221.             RefreshStrGad(&screenmodegads[SCREENMODE_HEIGHT-300],Window);
  222.     }
  223.     EnableGadget(&screenmodegads[SCREENMODE_DEPTH-300],rp,0,0);
  224.     RefreshStrGad(&screenmodegads[SCREENMODE_DEPTH-300],Window);
  225.     if (mode) {
  226.         if (mode->maxdepth==2 ||
  227.             (version2<OSVER_39 && 
  228.                 (mode->mode==MODE_WORKBENCHUSE || mode->mode==MODE_PUBLICSCREENUSE))) {
  229.             DisableGadget(&screenmodegads[SCREENMODE_DEPTH-300],rp,0,0);
  230.             FixSliderBody(Window,&screenmodegads[SCREENMODE_SLIDER-300],1,1,0);
  231.         }
  232.         else FixSliderBody(Window,&screenmodegads[SCREENMODE_SLIDER-300],mode->maxdepth-1,1,0);
  233.     }
  234.     FixSliderPot(Window,&screenmodegads[SCREENMODE_SLIDER-300],config->scrdepth-2,mode->maxdepth-1,1,2);
  235. }
  236.  
  237. void fixdefaultgads(mode)
  238. struct ScreenMode *mode;
  239. {
  240.     if (config->screenflags&SCRFLAGS_DEFWIDTH ||
  241.         mode->mode==MODE_WORKBENCHCLONE ||
  242.         mode->mode==MODE_PUBLICSCREENCLONE) {
  243.         config->screenflags|=SCRFLAGS_DEFWIDTH;
  244.         screenmodegads[SCREENMODE_DEFWIDTH-300].Flags|=SELECTED;
  245.         DisableGadget(&screenmodegads[SCREENMODE_WIDTH-300],rp,0,0);
  246.     }
  247.     else {
  248.         screenmodegads[SCREENMODE_DEFWIDTH-300].Flags&=~SELECTED;
  249.         EnableGadget(&screenmodegads[SCREENMODE_WIDTH-300],rp,0,0);
  250.     }
  251.     if (config->screenflags&SCRFLAGS_DEFHEIGHT ||
  252.         mode->mode==MODE_WORKBENCHCLONE ||
  253.         mode->mode==MODE_PUBLICSCREENCLONE) {
  254.         config->screenflags|=SCRFLAGS_DEFHEIGHT;
  255.         screenmodegads[SCREENMODE_DEFHEIGHT-300].Flags|=SELECTED;
  256.         DisableGadget(&screenmodegads[SCREENMODE_HEIGHT-300],rp,0,0);
  257.     }
  258.     else {
  259.         screenmodegads[SCREENMODE_DEFHEIGHT-300].Flags&=~SELECTED;
  260.         EnableGadget(&screenmodegads[SCREENMODE_HEIGHT-300],rp,0,0);
  261.     }
  262.     if (mode->maxdepth==2 ||
  263.         (version2<OSVER_39 && 
  264.             (mode->mode==MODE_WORKBENCHUSE || mode->mode==MODE_PUBLICSCREENUSE)))
  265.         DisableGadget(&screenmodegads[SCREENMODE_DEPTH-300],rp,0,0);
  266.     else EnableGadget(&screenmodegads[SCREENMODE_DEPTH-300],rp,0,0);
  267.  
  268.     EnableGadget(&screenmodegads[SCREENMODE_DEFWIDTH-300],rp,2,1);
  269.     EnableGadget(&screenmodegads[SCREENMODE_DEFHEIGHT-300],rp,2,1);
  270.     RefreshGList(&screenmodegads[SCREENMODE_DEFWIDTH-300],Window,NULL,2);
  271.     if (mode->mode==MODE_WORKBENCHCLONE || mode->mode==MODE_PUBLICSCREENCLONE) {
  272.         DisableGadget(&screenmodegads[SCREENMODE_DEFWIDTH-300],rp,2,1);
  273.         DisableGadget(&screenmodegads[SCREENMODE_DEFHEIGHT-300],rp,2,1);
  274.     }
  275. }
  276.  
  277. void sortscreenmodes(count,off)
  278. int count,off;
  279. {
  280.     int gap,i,j;
  281.     struct ScreenMode *mode1,*mode2;
  282.  
  283.     for (gap=count/2;gap>0;gap/=2)
  284.         for (i=gap;i<count;i++)
  285.             for (j=i-gap;j>=0;j-=gap) {
  286.                 mode1=getscreenmode(j+off);
  287.                 mode2=getscreenmode(j+gap+off);
  288.                 if (!mode1 || !mode2 || LStrCmpI(mode1->name,mode2->name)<=0) break;
  289.                 SwapMem((char *)mode1->name,(char *)mode2->name,sizeof(struct ScreenMode)-4);
  290.             }
  291. }
  292.  
  293. struct ScreenMode *getscreenmode(m)
  294. int m;
  295. {
  296.     struct ScreenMode *mode;
  297.     int a;
  298.  
  299.     mode=firstmode;
  300.     for (a=0;a<m;a++) {
  301.         if (!mode) break;
  302.         mode=mode->next;
  303.     }
  304.     return(mode);
  305. }
  306.